#encoding: utf-8
class UserSessionsController < ApplicationController

  layout 'native'
  def new
    @user_session = UserSession.new
    respond_to do |format|
      format.html # index.html.erb
      format.json { render :json=>{:notice => "请先登录" } }
    end
  end

  def create
    @user_session = UserSession.new(params[:user_session])
    if @user_session.save
      #flash[:notice] = "Login successful!"
      redirect_to :root #设置登录后的地址
    else
      flash.now[:notice] = "无效的用户名或密码"
      render :action => :new
    end
  end

  def destroy
    logger.info "start destroy"
    current_user_session.destroy if current_user_session
    #reset_session
    logger.info "start destroy"

    redirect_to :root
  end

  skip_before_filter :require_login
end
